package com.xxx.pojo.bean;

import java.io.Serializable;

/**
 * 接口返回基类（不带业务数据）
 */
public class BaseDTO implements Serializable {
	
	private static final long serialVersionUID = 6581552495571750682L;
	
	// 成功
    protected static final int SUCCESS = 200;
    protected static final String MSG_SUCCESS = "success";
    
    // 失败
    protected static final int FAILD = 100;
    protected static final String MSG_FAILD = "fail";
    
    // 无效请求
    protected static final int INVALID_REQUEST = 101;
    protected static final String MSG_INVALID_REQUEST = "非法请求";
    
    // 入参有误
    protected static final int ERROR_PARAM = 102;
    protected static final String MSG_ERROR_PARAM = "入参有误.";

    // 请求header缺少鉴权参数
    protected static final int INVALID_HEADER = 103;
    protected static final String MSG_INVALID_HEADER = "请求头不包含 [timestamp|nonce|sign|fingerprint]";

    // 异常
    protected static final int EXCEPTION = 500;
    protected static final String MSG_EXCEPTION = "发生异常";
    
    // 需要登录才能访问的未登录
    protected static final int NOT_LOGON = 401;
    protected static final String MSG_NOT_LOGIN = "未登录";

    // TOKEN过期
    protected static final int TOKEN_EXPIRED = 402;
    protected static final String MSG_TOKEN_EXPIRED = "登录已过期，请重新登录";

	private int code;
	private String msg;

	public BaseDTO(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

    public static BaseDTO builtSuccess() {
        return new BaseDTO(SUCCESS, MSG_SUCCESS);
    }

    public static BaseDTO builtFail(String msg) {
        return new BaseDTO(FAILD, msg);
    }

    public static BaseDTO builtFail(int code, String msg) {
        return new BaseDTO(code, msg);
    }

	public static BaseDTO builtInvalidRequest() {
		return new BaseDTO(INVALID_REQUEST, MSG_INVALID_REQUEST);
	}

	public static BaseDTO builtInvalidRequest(String msg) {
		return new BaseDTO(INVALID_REQUEST, msg);
	}

	public static BaseDTO builtErrorParam() {
		return new BaseDTO(ERROR_PARAM, MSG_ERROR_PARAM);
	}

	public static BaseDTO builtErrorParam(String msg) {
		return new BaseDTO(ERROR_PARAM, msg);
	}

	public static BaseDTO builtInvalidHeader() {
		return new BaseDTO(INVALID_HEADER, MSG_INVALID_HEADER);
	}

    public static BaseDTO builtException() {
        return new BaseDTO(EXCEPTION, MSG_EXCEPTION);
    }

	public static BaseDTO builtNotLogin() {
		return new BaseDTO(NOT_LOGON, MSG_NOT_LOGIN);
	}

	public static BaseDTO builtTokenExpired() {
		return new BaseDTO(TOKEN_EXPIRED, MSG_TOKEN_EXPIRED);
	}

}
